﻿using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using MyAnimelistRecommender.DataObject;

namespace MyAnimelistRecommender.Converter
{
    internal class GroupCheckboxConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            if (value == null) return null;
            System.Collections.ObjectModel.ReadOnlyObservableCollection<object> list = value as System.Collections.ObjectModel.ReadOnlyObservableCollection<object>;
            if (list.Count(x => (x as Anime).IsActivated) == list.Count)
                return true;
            else if (list.Count(x => !(x as Anime).IsActivated) == list.Count)
                return false;
            else return null;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}